package cn.sdormitory.controller.exam;

import cn.sdormitory.common.api.CommonPage;
import cn.sdormitory.common.api.CommonResult;
import cn.sdormitory.exam.entity.ClassroomTest;
import cn.sdormitory.exam.service.ClassroomTestService;
import cn.sdormitory.exam.vo.ClassroomTestRecordVo;
import cn.sdormitory.exam.vo.ClassroomTestVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : yy
 * @date: 2024/12/31 11:28
 * @description:
 */
@RestController
@Api(tags = "课堂测试管理")
@RequestMapping("/classroom/test")
public class ClassroomTestController {
    @Resource
    private ClassroomTestService classroomTestService;

    @ApiOperation("课堂测试管理-分页查询")
    @GetMapping("/getList")
    public CommonResult<CommonPage<ClassroomTestVo>> getList(
            @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
            @RequestParam(value = "testName", required = false) String testName,
            @RequestParam(value = "courseId", required = false) Integer courseId,
            @RequestParam(value = "classId", required = false) Integer classId
    ) {
        CommonPage<ClassroomTestVo> list = classroomTestService.getList(testName, courseId,classId, pageNum, pageSize);
        return CommonResult.success(list);
    }

    @ApiOperation("课堂测试管理-批量删除")
    @DeleteMapping(value = "/delTest/{ids}")
    public CommonResult delTest(@PathVariable Integer[] ids) {
        classroomTestService.delTest(ids);
        return CommonResult.success();
    }

    @ApiOperation(value = "课堂测试管理-根据id获取课堂测试信息")
    @GetMapping("/getTest/{id}")
    public CommonResult<ClassroomTest> getTest(@PathVariable("id") Integer id) {
        return CommonResult.success(classroomTestService.getTest(id));
    }

    @ApiOperation(value = "课堂测试管理-新增修改课堂测试信息")
    @PostMapping("/editTest")
    public CommonResult editTest(@RequestBody ClassroomTest classroomTest) {
        classroomTestService.editTest(classroomTest);
        return CommonResult.success();
    }

    @ApiOperation(value = "课堂测试管理-获取该课堂测试下班级学生的成绩记录")
    @GetMapping("/getClassroomTestRecord")
    public CommonResult<List<ClassroomTestRecordVo>> getClassroomTestRecord(@RequestParam("classId") Integer classId,
                                                                        @RequestParam("testId") Integer testId) {
        List<ClassroomTestRecordVo> list = classroomTestService.getClassroomTestRecord(classId,testId);
        return CommonResult.success(list);
    }

    @ApiOperation(value = "课堂测试管理-录入学生测试成绩")
    @PostMapping("/updateTestRecord/{id}")
    public CommonResult updateTestRecord(@PathVariable("id") Integer testId, @RequestBody List<ClassroomTestRecordVo> recordVos) {
        classroomTestService.updateTestRecord(testId,recordVos);
        return CommonResult.success();
    }
}
